<!--
 * @Author: your name
 * @Date: 2021-09-13 10:58:38
 * @LastEditTime: 2021-09-15 19:56:15
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \briup\6-jQuery\day02\xxtx\login.html
-->
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>登陆页面</title>
    <!-- jquery -->
    <script src="/briup/6-jQuery/js/jquery.js"></script>
    <!-- 最新版本的 Bootstrap 核心 CSS 文件 -->
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css" integrity="sha384-HSMxcRTRxnN+Bdg0JdbxYKrThecOKuH5zCYotlSAcp1+c8xmyTe9GYg1l9a69psu" crossorigin="anonymous">
    <!-- 最新的 Bootstrap 核心 JavaScript 文件 -->
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js" integrity="sha384-aJ21OjlMXNL5UyIl/XNwTMqvzeRMZH2w8c5cRVpzpU8Y5bApTppSuUkhZXN0VxHd" crossorigin="anonymous"></script>

</head>

<body>
    <div class="form-group">
        <label for="exampleInputName2">用户名：</label>
        <input type="text" class="form-control username" id="username" placeholder="username">
    </div>
    <div class="form-group">
        <label for="exampleInputEmail2">Email</label>
        <input type="password" class="form-control password" id="password" placeholder="password">
    </div>
    <button type="button" class="btn btn-default">登录</button>

</body>
<script>
    function login() {
        var obj = {
                //val() 返回被选元素的属性值
                username: $("#username").val(),
                password: $("#password").val()
            }
            //console.log(obj);
        $.ajax({
            url: "http://39.103.202.53:8888/user/login",
            method: "post",
            contentType: "application/json",
            data: JSON.stringify(obj),
            success: function(res) {
                console.log(res);
                sessionStorage.setItem("token", res.data.token);
                //attr() 返回被选元素的属性值
                $(location).attr("href", "./index.html");

            }
        })
    }
    $("button").click(login);
</script>

</html>